package Main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Sum {
	String url = "jdbc:mysql://localhost:3306/goods";
    String userName = "root";
    String password = "kamisama";
    String driverName = "com.mysql.jdbc.Driver";
    String strSql1 = "update sum set sum=price*num where id = ?";
    Scanner sc = new Scanner(System.in);
    	Connection con1 = null;
    	java.sql.PreparedStatement pstmt1 = null;
    	ResultSet rs1 = null;
    	String driverName2 = "com.mysql.jdbc.Driver";
	public void SumCargoods(int i){
		try {
			Class.forName(driverName2);// 加载MySql的驱动程序
	        con1 = (Connection) DriverManager.getConnection(url, userName, password); // 根据参数的插入数据
	        pstmt1 = con1.prepareStatement(strSql1);
	        pstmt1.setInt(1, i);
	        pstmt1.executeUpdate();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e){
			e.printStackTrace();
		}finally {
            if (rs1 != null)
                try {
                    rs1.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            if (pstmt1 != null){
                try {
                    pstmt1.close();// 关闭语句*/
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (con1 != null) {
                try {
                    con1.close();// 关闭连接
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
